<?php
	$dk="";
	if(isset($_GET["id"]) && $_GET["id"]!="") $dk="and concat('mn',idmenunhom)='".$_GET["id"]."'";
	include("../../include/dbconnect.php");

	function ChildCount($idmenunhom)
	{
		global $conn;
		$result=0;
		$rs=mysql_query("select * from menunhom where idmenunhom=$idmenunhom",$conn);
		$result=mysql_num_rows($rs);
		mysql_free_result($rs);
		return $result;
	}

	$table="menunhom";
	session_start();
	if(!isset($_SESSION["un"])) $_SESSION["un"]="";
	header("Content-Type: text/xml");
	echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
	echo "<root>\n";
	if($_SESSION["un"]!="")
	{
		$rs=mysql_query("select * from menunhom where chophep=1 $dk",$conn);
		while($a=mysql_fetch_array($rs))
		{
			$id=$a["id"];
			$parent_id=$a["idmenunhom"];
			if($parent_id=="") $parent_id=0; else $parent_id="mn".$parent_id;
			echo "	<item id=\"mn",$id,"\" parent_id=\"$parent_id\" state=\"closed\">\n";
			echo "		<content>\n";
			echo "			<name><![CDATA[",$a["ten"]," (",ChildCount($a["id"]),")","]]></name>\n";
			echo "		</content>\n";
			echo " 	</item>\n";
		}
		if($dk=="")
		{
			echo "	<item id=\"mn0\" parent_id=\"0\" state=\"closed\">\n";
			echo "		<content>\n";
			echo "			<name><![CDATA[Tạo nhóm menu gốc mới]]></name>\n";
			echo "		</content>\n";
			echo " 	</item>\n";
		}
		mysql_free_result($rs);
	}
	echo "</root>\n";
	include("../../include/dbclose.php");
?>